package com.mstanford.movie.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.mstanford.movie.dao.MovieDao;
import com.mstanford.movie.utils.DataUtil;

public class QuerySeatServlet extends HttpServlet {

	private static final long serialVersionUID = 1L;

	@Override
	protected void service(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		
		String playId = request.getParameter("playId");
		
		MovieDao dao = new MovieDao();
		Map<String, String> map = dao.queryMovieByPlayId(playId);
		List<String> list = dao.querySeatByPlayId(playId);
		
		String json1 = DataUtil.mapToJson(map);
		String json2 = DataUtil.list2Json(list);
		
		String json = "{\"movie\":" + json1 + ",\"seat\":" + json2 + "}";
		
		// 返回Json格式信息
		response.setContentType("application/json; charset=UTF-8");
		PrintWriter out = response.getWriter();
		
		out.print(json);
		out.flush();
		out.close();
	}
}